﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using WPFCustomControls.model;

namespace WPFCustomControls.views
{
    /// <summary>
    /// DataGridPagerPage.xaml 的交互逻辑
    /// </summary>
    public partial class DataGridPagerPage : Page
    {

        private DataGridPagerPageViewModel windowViewModel;

        public DataGridPagerPage()
        {
            InitializeComponent();

            windowViewModel = new DataGridPagerPageViewModel();
            this.DataContext = windowViewModel;
          
        }

        public void Query(int size, int pageIndex)
        {
            windowViewModel.Total = Student.Students.Count;
            windowViewModel.Students = Student.Students.Skip((pageIndex - 1) * size).Take(size).ToList();

        }

        private void PagingDataGrid_PagingChanged(object sender, DataGridPager.PagingChangedEventArgs args)
        {
            Query(args.PageSize, args.PageIndex);
        }
    }

    public class DataGridPagerPageViewModel : ViewModelBase
    {
        public int _total;
        public int Total
        {
            get
            {
                return _total;
            }
            set
            {
                if (_total != value)
                {
                    _total = value;
                    NotifyPropertyChanged();
                }
            }
        }

        private List<Student> _students;
        public List<Student> Students
        {
            get
            {
                return _students;
            }
            set
            {
                if (_students != value)
                {
                    _students = value;
                    NotifyPropertyChanged();
                }
            }
        }

        public DataGridPagerPageViewModel()
        {
            Students = new List<Student>();
        }
    }
}
